package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.PsyTest;
import com.hl.sfzy.service.PsyTestService;
import com.hl.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 1. @ClassDescription:
 * 2. @ClassName PsyTestController
 * 3. @Description TODO
 * 4. @Author: YuKunXu
 * 5. @Date: 2024年01月14日 23:09
 * 6. @Project: sfzy
 * 7. @Version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/psyTest")
public class PsyTestController {
    @Autowired
    private PsyTestService psyTestService;
    @PostMapping("/add")
    public Result add(@RequestBody PsyTest psyTest) throws Exception {
        psyTestService.add(psyTest);
        return Result.success();
    }

    /**
     * 编辑
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody PsyTest psyTest) {
        psyTestService.edit(psyTest);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        psyTestService.remove(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/remove")
    public Result removeBatch(Integer[] ids) {
        System.out.println(ids);
        psyTestService.removeBatch(ids);
        return Result.success();
    }

    /**
     * 单条查询
     */
    @GetMapping("/find/{id}")
    public Result findByPsyId(@PathVariable Integer id) {
        return Result.success(psyTestService.findByPsyId(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/find")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           PsyTest psyTest) {
        System.out.println(psyTest);
        return Result.success(psyTestService.findPage(pageNum, pageSize, psyTest));
    }

}